﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using A2DFramework.CacheService;
using System.Reflection;
using A2DFramework.SQLDispatcherService.SimpleADOdotNetDispatcher;
using A2DFramework.AOPService.Core;
using A2DFramework.InstanceService.Configuration;

namespace A2DFramework.InstanceService
{
    public static class ObjectFactory
    {
        public static bool IsRegistered(Type type)
        {
            return MapIoCService.IsTypeKeyExist(type);
        }
        public static  bool IsRegistered<T>()
        {
            Type t = typeof(T);
            return IsRegistered(t);
        }





        public static void Register(Type T, Type TProvider)
        {
            MapIoCService.RegisterMapping(T, TProvider, false);
        }
        public static void Register<T, TProvider>()
            where TProvider : class, T
        {
            MapIoCService.RegisterMapping(typeof(T), typeof(TProvider), false);
        }
        public static void RegisterAsSingleton<T, TProvider>()
        {
            MapIoCService.RegisterMapping(typeof(T), typeof(TProvider), true);
        }





        public static T Resolve<T>()
        {
            Type t = typeof(T);
            return (T)Resolve(t);
        }
        public static object Resolve(Type t)
        {
            if (!MapIoCService.IsTypeKeyExist(t))
                throw new Exception("Key empty, register please");

            return MapIoCService.ResolveInstance(t);
        }

        
    }
}
